package com.atguigu.gmall;


import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.util.ClassUtils;


public class FastDFSDemo {

    public static void main(String[] args) throws Exception{

        //1 加载客户端的配置文件 IO流  绝对路径
        String path = ClassUtils.class.getClassLoader().getResource("fdfs_client.conf").getPath();
        System.out.println("path = " + path);
        //path = /E:/workspace/cxgmall/gmall-parent/service/service-product/target/classes/fdfs_client.conf
        ClientGlobal.init(path);

        //2 链接tracker服务器
        TrackerClient trackerClient = new TrackerClient();
        //3 链接tracker
        TrackerServer trackerServer = trackerClient.getConnection();
        //4 升级版的storageClient1
        StorageClient1 storageClient1 = new StorageClient1(trackerServer, null);
        //5 上传文件
        String file_id = storageClient1.upload_file1(
                "E:\\尚品汇商城\\资料\\图片\\Apple11\\08fed8837c92433a.jpg",
                "jpg",null);
        System.out.println("file_id = " + file_id);
        //  file_id = group1/M00/00/00/wKgVgGDjkoqAF0nGAAIbO5uH5xk041.jpg
        //  http://192.168.21.128:8080/group1/M00/00/00/wKgVgGDjkoqAF0nGAAIbO5uH5xk041.jpg
    }
}
